<?php
class customer extends head {
 function customer() {
  $this->table = "customer";
  $this->getmetadata();
  $this->maintainhist = true;
  $this->header[2] = "";
  $_SESSION[$this->table] = $this;
 }
 function createblank() {
  parent::createblank();  
  $this->header[16] = dtoiso();
  $this->header[16] = dtoiso();
  $this->header[17] = 0;
  $this->header[21] = '1';
  $this->header[25] = '1';
  $this->header[27] = '1';
 }
 function newcounter() {
  return getcounter('CUS','1');
 }
 function showform() {
  echo '<head>';
  echo SCRIPTS;
  echo '</head>';
	echo "<body onload='document.form.f1.focus()'>";
  echo "<h1>Customer Setup</h1>"; 
  echo "<form name='form' method=GET>";
  echo "<input type=hidden name=res value=''>";
  echo "<table>";
  echo $this->htmlrow('0','Code','Disabled');
  echo $this->htmlrow('1');
  echo $this->htmlrow('5');
  echo $this->htmlrow('6');
  echo $this->htmlrow('7');
  echo $this->htmlrow('8');
  echo $this->htmlrow('9');
  echo $this->htmlrow('27','GST Code');
  echo "</table>";
  echo '<input class=bt accesskey=A type=submit name=sub value=Apply>';
  echo '<input class=bt accesskey=S type=submit name=sub value=Save>';
  echo '<button class=bt onclick=rest()><span>Restart</span></button>'; 
  echo "</form>"; 
 }
 function applyfromrequest() {
  $this->valid = true;
  // Goes through request. Applies if legal, otherwise error.
  $this->valids = array_fill(0,$this->atts,'');

  $i = 1;
	if ($f=@$_REQUEST["f$i"]) {
	 $size = $this->metadata[$i]->length ;
   // name. Allowable characters A-Za-z-space apostrophe
   if(preg_match("/^[0-9 a-z A-Z\'\.-]{0,$size}$/",$f)) {
    $this->header[$i] = $f; 
   } else {
    $this->valids[$i] = "Please enter a valid name";
   }
  }

  $i = 5;
	if ($f=@$_REQUEST["f$i"]) {
	 $size = $this->metadata[$i]->length ;
   // name. Allowable characters A-Za-z-space apostrophe
   if(preg_match("/^[0-9 a-z A-Z\'\.-]{0,$size}$/",$f)) {
    $this->header[$i] = $f; 
   } else {
    $this->valids[$i] = "Please enter a valid name";
   }
  }
  
  $i = 6;
	if ($f=@$_REQUEST["f$i"]) {
	 $size = $this->metadata[$i]->length ;
   // name. Allowable characters A-Za-z-space apostrophe
   if(preg_match("/^[0-9 a-z A-Z\'\.-]{0,$size}$/",$f)) {
    $this->header[$i] = $f; 
   } else {
    $this->valids[$i] = "Please enter a valid name";
   }
  }
  
  $i = 7;
	if ($f=@$_REQUEST["f$i"]) {
	 $size = $this->metadata[$i]->length ;
   // name. Allowable characters A-Za-z-space apostrophe
   if(preg_match("/^[0-9 a-z A-Z\'\.-]{0,$size}$/",$f)) {
    $this->header[$i] = $f; 
   } else {
    $this->valids[$i] = "Please enter a valid name";
   }
  }
  
  $i = 8;
	if ($f=@$_REQUEST["f$i"]) {
	 $size = $this->metadata[$i]->length ;
   // name. Allowable characters A-Za-z-space apostrophe
   if(preg_match("/^[0-9 a-z A-Z\'\.-]{0,$size}$/",$f)) {
    $this->header[$i] = $f; 
   } else {
    $this->valids[$i] = "Please enter a valid name";
   }
  }
  $i = 9;
	if ($f=@$_REQUEST["f$i"]) {
	 $size = $this->metadata[$i]->length ;
   // name. Allowable characters A-Za-z-space apostrophe
   if(preg_match("/^[0-9 a-z A-Z\'\.-]{0,$size}$/",$f)) {
    $this->header[$i] = $f; 
   } else {
    $this->valids[$i] = "Please enter a valid name";
   }
  }
  
  $i=18;
	if ($f=@$_REQUEST["f$i"]) {
   // Code of GST object
   $desc = freaditem('GST',$f);
   if ($desc == '') {
    $this->valids[$i] = 'Need valid Currency Code';
    $this->lists[$i] = $this->selectlisth('Currency',$f,"f$i");
   } else {
    $this->header[$i] = $f;
    $this->refs[$i] = $desc[1];
    $this->lists[$i] = '';
   }
  }  
  
  
  $i=27;
	if ($f=@$_REQUEST["f$i"]) {
   // Code of GST object
   $desc = freaditem('GST',$f);
   if ($desc == '') {
    $this->valids[$i] = 'Need valid GST code';
    $this->lists[$i] = $this->selectlisth('GST',$f,"f$i");
   } else {
    $this->header[$i] = $f;
    $this->refs[$i] = $desc[1];
    $this->lists[$i] = '';
   }
  }  
  
  $this->valid = every($this->valids,"");
  if ($this->valid) {
   if ($this->header[1] == "") $this->valids[1] = "Incomplete";
   $this->valid = every($this->valids,"");   
  }
   
 }
}
?>